package com.xrkj.b2c.service.impl.sys;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.xrkj.b2c.dao.sys.SysMemberMapper;
import com.xrkj.b2c.exception.DataAccessException;
import com.xrkj.b2c.model.sys.SysMember;
import com.xrkj.b2c.service.sys.SysMemberService;
import com.xrkj.b2c.utils.DateUtils;

/**
 * 
 * <B>系统名称：</B><BR>
 * <B>模块名称：</B><BR>
 * <B>中文类名：</B>会员服务类<BR>
 * <B>概要说明：</B><BR>
 * @author 赵子靖
 * @since 2018年07月15日
 */
@Service
public class SysMemberServiceImpl implements SysMemberService{
    @Autowired
    private SysMemberMapper sysMemberDao;
    
    
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public int deleteByPrimaryKey(String id) {
        return sysMemberDao.deleteByPrimaryKey(id);
    }
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public int insert(SysMember record) {
        return sysMemberDao.insert(record);
    }
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public int insertSelective(SysMember record) {
        return sysMemberDao.insertSelective(record);
    }
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public SysMember selectByPrimaryKey(String id) {
        return sysMemberDao.selectByPrimaryKey(id);
    }
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public int updateByPrimaryKeySelective(SysMember record) {
        return sysMemberDao.updateByPrimaryKeySelective(record);
    }
    @Transactional(readOnly=false,propagation = Propagation.REQUIRED,rollbackFor=DataAccessException.class)
    public int updateByPrimaryKey(SysMember record) {
        return sysMemberDao.updateByPrimaryKey(record);
    }

    /**
     * 
     * <B>方法名称：</B>根据用户名和密码获取信息<BR>
     * <B>概要说明：</B><BR>
     * @see com.xrkj.b2c.service.sys.SysMemberService#findSysMemberByLoginNameAndPwd(java.util.Map)
     */
    @Transactional(readOnly=true,propagation = Propagation.REQUIRED)
    public SysMember findMemberByAccountAndPwd(Map<String, Object> ret) {
        return sysMemberDao.findMemberByAccountAndPwd(ret);
    }
	
    /**
     * 
     * <B>方法名称：</B>获取列表<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年11月9日
     * @param paramter
     * @return
     */
    public Integer findMemberTotal(Map<String, Object> paramter){
        return sysMemberDao.findMemberTotal(paramter);
    }

    /**
     * 
     * <B>方法名称：</B>获取记录数<BR>
     * <B>概要说明：</B><BR>
     * 
     * @author perry
     * @since 2017年11月9日
     * @param paramter
     * @return
     */
    public List<SysMember> findMemberList(Map<String, Object> paramter){
        return sysMemberDao.findMemberList(paramter);
    }
	
    /**
     * 
     * <B>方法名称：</B>生成会员编号<BR>
     * <B>概要说明：</B><BR>
     * @author perry
     * @since 2017年12月12日   
     * @return
     */
    public String createMemberNo(){
        StringBuffer memberNo = new StringBuffer();
        Integer total = sysMemberDao.findMemberTotal(null);
        if(total==null){
            total = 1;
        }else{
            total += 1;
        }
        String memberTotal = "00001";
        if(total<10){
            memberTotal="0000"+(total);
        }else if(total<100){
            memberTotal="000"+(total);
        }else if(total<1000){
            memberTotal="00"+(total);
        }else if(total<10000){
            memberTotal="0"+(total);
        }else if(total<100000){
            memberTotal=String.valueOf(total);
        }
        memberNo.append("WH").append(DateUtils.genYMD()).append(memberTotal);
        return memberNo.toString();       
    }
}
